import '../Scss/TestDataList.scss'
import dayjs from 'dayjs'
import { Http } from '../../Api'
import { API_LIST } from '../../Api/Api'
import request from 'umi-request'
import { useState, useEffect, useRef, Fragment } from 'react'
import { Area } from '@ant-design/plots'
import { useRequest, useSize, useBoolean, useEventEmitter, useMount } from 'ahooks'
import { Button, TreeSelect, message, Tabs, Descriptions, Spin, Result, Select, Input, DatePicker } from 'antd'
import { Video } from '../../Configure/Video'
import { ModalBox } from '../ModalBox'
import { Line } from '@ant-design/plots'
import { ProTable } from '@ant-design/pro-components'

import { DescriptionsModal } from '../../Router/MenuNav/module/DescriptionsModal'
import { commonTableList } from '../../Router/MenuNav/Common/common'
import {
    AddDataButton,
    ModDataButton,
    AnnexButton,
    DelDataButton,
    PrintQRCodeButton,
    SaveExcelButton,
    OpenExcelButton,
    CommonButton,
} from '../../Router/MenuNav/Common/options'
import { LabReportTemplates } from '../../Router/MenuNav/Common/Conversion'
import { ExportExcel } from '../../Configure/QRcode'

const { TextArea } = Input

// 力值等折线图
export const LineChartsModal = ({ data }) => {
    const { chartsData, chartsSetUp } = data.data
    const ChartsBox = useRef()
    const size = useSize(ChartsBox)
    const LineSetUp = size => {
        const { width, height } = size
        return {
            data: chartsData,
            width,
            height,
            autoFit: false,
            appendPadding: 32,
            xField: 'label',
            ...chartsSetUp,
        }
    }
    return (
        <div className="LineChartsModal" ref={ChartsBox}>
            {size && <Line {...LineSetUp(size)} />}
        </div>
    )
}
// 张拉压浆匹配
export const TAPMate = ({ data, Off }) => {
    const [messageApi, contextHolder] = message.useMessage()
    const { url, componentId, actionRef } = data.data

    const [Value, setValue] = useState()
    const [options, setOptions] = useState([])

    const { runAsync: posData } = useRequest(Http, { manual: true })
    const { runAsync: getData } = useRequest(Http, {
        manual: true,
        onSuccess: res => {
            const data = res.map(item => ({ beamNo: item.bridgeFullName, beamUuid: item.bridgeFullName, ...item }))
            setOptions(data)
        },
    })
    useEffect(() => {
        getData({ url: 'getLabTensionBridgeBeams' })
    }, [getData])

    const submit = () => {
        if (!Value || Value.length !== 36) {
            messageApi.info('请选择梁编号')
            return false
        }

        posData({ url, data: { componentId, beamUuid: Value } }).then(() => {
            actionRef.current.reload()
            Off()
        })
    }

    return (
        <div className="SelectModal">
            {contextHolder}
            <div>
                <div>桥梁 : </div>
                <TreeSelect
                    fieldNames={{ label: 'beamNo', value: 'beamUuid', children: 'beams' }}
                    treeData={options}
                    showSearch
                    treeDefaultExpandAll
                    value={Value}
                    onChange={e => setValue(e)}
                    treeNodeFilterProp="beamNo"
                />
            </div>
            <div>
                <Button type="primary" onClick={submit}>
                    匹配结果
                </Button>
            </div>
        </div>
    )
}

// 张拉压浆详情
export const TAPDetails = ({ data }) => {
    const { type, children, beamUuid } = data.data
    const ChartsBox = useRef()
    const size = useSize(ChartsBox)
    const { runAsync } = useRequest(Http, { margin: true })
    const [active, setActive] = useState({})
    const [items, setItems] = useState([])
    const [CameraData, setCameraData] = useState()

    const Active = e => setActive(children.find(v => v.uuid === e))

    const TypeList = {
        LabTension: {
            columns: [
                { label: '当前桥梁', value: beamUuid[active.beamUuid] },
                { label: '张拉断面', value: active.tensioningSection },
                { label: '张拉时间', value: active.tensioningDate },
                { label: '张拉力0', value: active.tensioningForce0 },
                { label: '张拉力1', value: active.tensioningForce1 },
                { label: '张拉力2', value: active.tensioningForce2 },
                { label: '张拉力3', value: active.tensioningForce3 },
                { label: '张拉力4', value: active.tensioningForce4 },
                { label: '伸长量0', value: active.elongation0 },
                { label: '伸长量1', value: active.elongation1 },
                { label: '伸长量2', value: active.elongation2 },
                { label: '伸长量3', value: active.elongation3 },
                { label: '伸长量4', value: active.elongation4 },
                { label: '油压0', value: active.oilPressure0 },
                { label: '油压1', value: active.oilPressure1 },
                { label: '油压2', value: active.oilPressure2 },
                { label: '油压3', value: active.oilPressure3 },
                { label: '油压4', value: active.oilPressure4 },
                { label: '设计张拉控制力', value: active.theoreticalElongation },
                { label: '总抻长量', value: active.totalElongation },
            ],
            charts: [
                {
                    title: '张拉曲线(Kn)',
                    data: 'forceCurve',
                    value: '力量',
                    fill: 'l(270) 0:#ffffff 0.5:#bae0ff 1:#1677ff',
                    color: '#1677ff',
                },
                {
                    title: '伸长曲线(mm)',
                    data: 'elongationCurve',
                    value: '长度',
                    fill: 'l(270) 0:#ffffff 0.5:#ffffb8 1:#fadb14',
                    color: '#fadb14',
                },
            ],
        },
        LabPulping: {
            columns: [
                { label: '当前桥梁', value: beamUuid[active.beamUuid] },
                { label: '压浆方向', value: active.pulpingOrientation },
                { label: '压浆时间', value: active.loadHoldingTime },
                { label: '配合比', value: active.mixProportion },
                { label: '水胶比', value: active.waterBinderRatio },
                { label: '搅拌时间', value: active.stirringTime },
                { label: '开始时间', value: active.startDate },
                { label: '结束时间', value: active.endDate },
                { label: '进浆压力', value: active.pulpingPressureIn },
                { label: '出浆压力', value: active.pulpingPressureOut },
                { label: '进浆量', value: active.pulpingVolume },
                { label: '理论浆量', value: active.standardVolume },
            ],
            charts: [
                {
                    title: '进浆压力曲线(Kn)',
                    data: 'pressureInCurve',
                    value: '力量',
                    fill: 'l(270) 0:#ffffff 0.5:#bae0ff 1:#1677ff',
                    color: '#1677ff',
                },
                {
                    title: '进浆量曲线(L)',
                    data: 'volumeCurve',
                    value: '升',
                    fill: 'l(270) 0:#ffffff 0.5:#ffffb8 1:#fadb14',
                    color: '#fadb14',
                },
            ],
        },
    }

    const AreaFunc = ({ value, fill, color, data }) => {
        const { width, height } = size
        const list = data.split(',').map((item, index) => ({ type: index, [value]: Number(item) }))
        return {
            autoFit: false,
            data: list,
            width,
            height: height / 2 - 40,
            appendPadding: 16,
            xField: 'type',
            yField: value,
            color: color,
            xAxis: { range: [0, 1], tickCount: 5 },
            areaStyle: () => ({ fill }),
        }
    }

    useEffect(() => {
        if (JSON.stringify(active) !== '{}' && active.cameraUuids.length !== 0)
            runAsync({ url: 'getCamera', data: { cameraUuid: active.cameraUuids[0] } }).then(res =>
                setCameraData(res.list[0]),
            )
        else setCameraData()
    }, [active, runAsync])

    useEffect(() => {
        const items = children.map(item => ({
            label: `${item.steelBeamNo}${item.tensioningSection || ''}`,
            key: item.uuid,
        }))
        setActive(children.find(v => v.uuid === items[0].key))
        setItems(items)
    }, [children])

    return (
        <div className="TAPDetails">
            <Tabs activeKey={active.uuid} items={items} centered onChange={Active} />
            <div className="Box">
                <div className="Left">
                    <Descriptions bordered size="small" column={1}>
                        {TypeList[type].columns.map(({ label, value }, index) => (
                            <Descriptions.Item key={index} label={label}>
                                {value}
                            </Descriptions.Item>
                        ))}
                    </Descriptions>
                    <div> {CameraData ? <Video data={CameraData} /> : '暂无监控画面'} </div>
                </div>
                <div className="Right" ref={ChartsBox}>
                    {TypeList[type].charts.map(({ title, value, fill, color, data }, index) => (
                        <div key={index}>
                            <div>{title}</div>
                            {size && <Area {...AreaFunc({ value, fill, color, data: active[data] })} />}
                        </div>
                    ))}
                </div>
            </div>
        </div>
    )
}

// 压力机详情
export const LabStressMachine = ({ data }) => {
    const { runAsync } = useRequest(Http, { manual: true })
    const testEvaluationList = { 0: '合格', 1: '不合格', 2: '无效', 3: '作废' }
    const [Data, setData] = useState()
    const [Length, setLength] = useState()
    const [loadValue, setLoadValue] = useState()
    const [compressive, setCompressive] = useState()
    const [processStress, setProcessStress] = useState()
    const [OptionsCall, setOptionsCall] = useState()

    useEffect(() => {
        const { uuid } = data.data
        runAsync({ url: 'getLabStressMachineID', path: [uuid] }).then(res => {
            const { cubeCount, loadValue, compressiveStrength, processStress } = res
            setData(res)
            setLength(cubeCount)
            setLoadValue(loadValue.split(','))
            setCompressive(compressiveStrength.split(','))
            setProcessStress(JSON.parse(processStress))
        })
    }, [data, runAsync])

    return (
        <div>
            <Descriptions bordered style={{ marginBottom: 8, background: 'white' }}>
                <Descriptions.Item label="试验机名称" span={3}>
                    {Data?.equipmentName}
                </Descriptions.Item>
                <Descriptions.Item label="试件编号">{Data?.cubeCode}</Descriptions.Item>
                <Descriptions.Item label="试验日期">{Data?.testDate}</Descriptions.Item>
                <Descriptions.Item label="试验面积">{Data?.cubeArea}</Descriptions.Item>
                <Descriptions.Item label="设计强度">{Data?.designStrength}</Descriptions.Item>
                <Descriptions.Item label="强度代表值">{Data?.representativeStrength}</Descriptions.Item>
                <Descriptions.Item label="评定结果">{testEvaluationList[Data?.testEvaluation]}</Descriptions.Item>
            </Descriptions>
            <Descriptions bordered style={{ background: 'white' }}>
                <Descriptions.Item label="试验类型" span={3}>
                    {Data?.testType}
                </Descriptions.Item>
                {Length &&
                    [...new Array(Length).keys()].map(key => (
                        <Fragment key={key}>
                            <Descriptions.Item label="荷载力值">{loadValue[key]}</Descriptions.Item>
                            <Descriptions.Item label="抗折/抗压强度"> {compressive[key]} </Descriptions.Item>
                            <Descriptions.Item label="详情">
                                <Button
                                    type="link"
                                    onClick={() => {
                                        const chartsData = processStress[key]
                                            .split(',')
                                            .map((item, index) => ({ 力值: Number(item), label: index }))
                                        const chartsSetUp = {
                                            yField: '力值',
                                            xAxis: {
                                                title: {
                                                    text: '时间/s',
                                                    position: 'end',
                                                    offsetX: 0,
                                                    style: { fill: '#262626', fontSize: 12 },
                                                },
                                                label: { style: { fill: '#262626', fontSize: 12 } },
                                            },
                                            yAxis: {
                                                title: {
                                                    text: '力值/KN',
                                                    position: 'end',
                                                    spacing: 24,
                                                    autoRotate: false,
                                                    style: { fill: '#262626', fontSize: 12 },
                                                },
                                                label: { style: { fill: '#262626', fontSize: 12 } },
                                            },
                                        }
                                        setOptionsCall({
                                            type: 'LineChartsModal',
                                            data: { title: '力值曲线', data: { chartsData, chartsSetUp } },
                                        })
                                    }}
                                >
                                    力值曲线
                                </Button>
                                <Button
                                    type="link"
                                    onClick={() => {
                                        const { originalDataTable, labHandleTypeUuid, startTime, endTime, testDate } =
                                            Data
                                        setOptionsCall({
                                            type: 'MonitorVideo',
                                            data: {
                                                title: '试验监控回放',
                                                data: {
                                                    url: 'getLabDataCameraByOriginalDataTable',
                                                    originalDataTable,
                                                    labHandleTypeUuid,
                                                    startTime,
                                                    endTime,
                                                    testDate,
                                                },
                                            },
                                        })
                                    }}
                                >
                                    视频回放
                                </Button>
                            </Descriptions.Item>
                        </Fragment>
                    ))}
            </Descriptions>
            <ModalBox OptionsCall={OptionsCall} />
        </div>
    )
}

// 万能机试验详情
export const LabUniversalRebar = ({ data }) => {
    const ClientData = JSON.parse(localStorage.getItem('ClientData'))
    const [messageApi, contextHolder] = message.useMessage()
    const { runAsync: getData } = useRequest(Http, { manual: true })
    const { runAsync: getLine } = useRequest(Http, { manual: true })
    const [Data, setData] = useState([])
    const [OptionsCall, setOptionsCall] = useState()

    useEffect(() => {
        const { groupId } = data.data
        getData({
            url: 'getLabDataByDisplayNo',
            data: { pageSize: 1000, displayNo: groupId, originalDataTable: 'Lab_LabUniversalRebar' },
        }).then(res => setData(res.list))
    }, [data, getData])

    const getLinkFun = (uuid, type) => {
        getLine({
            url: 'getLabProcessDataByUuid',
            data: { uuid, originalDataTable: 'Lab_LabUniversalRebar' },
        }).then(res => {
            const [{ timeProcess, forceProcess, displacementProcess }] = res.list
            if (type === 0) {
                if (!forceProcess) messageApi.info('暂无力值数据')
                else AssembleFun(type, timeProcess, forceProcess)
            } else {
                if (!displacementProcess) messageApi.info('暂无位移数据')
                else AssembleFun(type, timeProcess, displacementProcess)
            }
        })
    }
    const AssembleFun = (type, time, data) => {
        const typeList = [
            { value: '力值', text: '力值/KN', title: '力值曲线' },
            { value: '位移', text: '位移/mm', title: '位移曲线' },
        ]
        const dataArr = data.split(',')
        const timeArr = time.split(',')
        const { value, text, title } = typeList[type]
        const chartsData = dataArr.map((item, index) => ({ [value]: Number(item), label: timeArr[index] }))
        const chartsSetUp = {
            yField: value,
            xAxis: {
                title: {
                    text: '时间/s',
                    position: 'end',
                    offsetX: 0,
                    style: { fill: '#262626', fontSize: 12 },
                },
                label: { style: { fill: '#262626', fontSize: 12 } },
            },
            yAxis: {
                title: {
                    text,
                    position: 'end',
                    spacing: 24,
                    autoRotate: false,
                    style: { fill: '#262626', fontSize: 12 },
                },
                label: { style: { fill: '#262626', fontSize: 12 } },
            },
        }
        setOptionsCall({
            type: 'LineChartsModal',
            data: { title, data: { chartsData, chartsSetUp } },
        })
    }

    return (
        <div className="LabUniversalRebar">
            {contextHolder}
            {Data.map(item => (
                <Descriptions
                    key={item.uuid}
                    size="small"
                    column={4}
                    layout="vertical"
                    bordered
                    style={{ background: 'white' }}
                >
                    <Descriptions.Item label="试验类别" span={2}>
                        {item.testType}
                    </Descriptions.Item>
                    <Descriptions.Item label="试验时间" span={2}>
                        {item.testDate}
                    </Descriptions.Item>
                    <Descriptions.Item label="组织机构">
                        {ClientData.organization[item.organizationUuid]}
                    </Descriptions.Item>
                    <Descriptions.Item label="试验组号">{item.groupName}</Descriptions.Item>
                    <Descriptions.Item label="试件序号">{item.testCode}</Descriptions.Item>
                    <Descriptions.Item label="评定结果">{item.result}</Descriptions.Item>
                    <Descriptions.Item label="公称直径">{item.nominalDiameter}</Descriptions.Item>
                    <Descriptions.Item label="公称截面面积">{item.nominalSectionalArea}</Descriptions.Item>
                    <Descriptions.Item label="屈服力Fs(kN)">{item.lowerYield}</Descriptions.Item>
                    <Descriptions.Item label="屈服点RP(MPa)">{item.lowerYieldStrength}</Descriptions.Item>
                    <Descriptions.Item label="拉断最大力Fm(kN)">{item.maximumForce}</Descriptions.Item>
                    <Descriptions.Item label="抗拉强度Rm(MPa)">{item.bendingStrength}</Descriptions.Item>
                    <Descriptions.Item label="断后伸长率A(%)">{item.elongationPctAfter}</Descriptions.Item>
                    <Descriptions.Item label="最大力总延伸率(%)">{item.maximumTotalElongation}</Descriptions.Item>
                    <Descriptions.Item label="最大力总延伸率(%)">
                        <div className="options">
                            <Button type="primary" onClick={() => getLinkFun(item.uuid, 0)}>
                                力值曲线
                            </Button>
                            <Button type="primary" onClick={() => getLinkFun(item.uuid, 1)}>
                                位移曲线
                            </Button>
                            <Button
                                type="primary"
                                onClick={() => {
                                    const { originalDataTable, labHandleTypeUuid, startTime, endTime, testDate } = item
                                    setOptionsCall({
                                        type: 'MonitorVideo',
                                        data: {
                                            title: '试验监控回放',
                                            data: {
                                                url: 'getLabDataCameraByOriginalDataTable',
                                                originalDataTable,
                                                labHandleTypeUuid,
                                                startTime,
                                                endTime,
                                                testDate,
                                            },
                                        },
                                    })
                                }}
                            >
                                监控记录
                            </Button>
                        </div>
                    </Descriptions.Item>
                </Descriptions>
            ))}
            <ModalBox OptionsCall={OptionsCall} />
        </div>
    )
}

// 水泥拌合站详情
export const CementMixingStations = ({ data }) => {
    const { runAsync } = useRequest(Http, { manual: true })
    const [Data, setData] = useState()
    const [OneData, setOneData] = useState(['实际配⽐'])
    const [TwoData, setTwoData] = useState(['施⼯配⽐'])
    const TitleList = [
        '材料名称',
        '水1',
        '水2',
        '水泥1',
        '水泥2',
        '水泥3',
        '砂1',
        '砂2',
        '碎石1',
        '碎石2',
        '碎石3',
        '碎石4',
        '矿粉',
        '粉煤灰',
        '减水剂',
    ]
    useEffect(() => {
        const { url, uuid } = data.data
        runAsync({ url, path: [uuid] }).then(res => {
            const dataOne = [
                '实际配⽐',
                res.water1Act,
                res.water2Act,
                res.cement1Act,
                res.cement2Act,
                res.cement3Act,
                res.sand1Act,
                res.sand2Act,
                res.gravel1Act,
                res.gravel2Act,
                res.gravel3Act,
                res.gravel4Act,
                res.slagPowderAct,
                res.flyashAct,
                res.waterReducerAct,
            ]
            const dataTwo = [
                '施⼯配⽐',
                res.water1Oper,
                res.water2Oper,
                res.cement1Oper,
                res.cement2Oper,
                res.cement3Oper,
                res.sand1Oper,
                res.sand2Oper,
                res.gravel1Oper,
                res.gravel2Oper,
                res.gravel3Oper,
                res.gravel4Oper,
                res.slagPowderOper,
                res.flyashOper,
                res.waterReducerOper,
            ]
            setOneData(dataOne)
            setTwoData(dataTwo)
            setData(res)
        })
    }, [data, runAsync])
    return (
        <div className="MixingStations">
            {Data && (
                <Descriptions size="small" layout="vertical" bordered>
                    <Descriptions.Item label="设备编号">{Data.code}</Descriptions.Item>
                    <Descriptions.Item label="出料时间">{Data.dischargingTime}</Descriptions.Item>
                    <Descriptions.Item label="上传时间">{Data.uploadTime}</Descriptions.Item>
                    <Descriptions.Item label="施工配合比编号">{Data.proportionOperId}</Descriptions.Item>
                    <Descriptions.Item label="工程名">{Data.projectName}</Descriptions.Item>
                    <Descriptions.Item label="浇筑部位">{Data.pouringPosition}</Descriptions.Item>
                    <Descriptions.Item label="强度等级">{Data.strengthGrade}</Descriptions.Item>
                    <Descriptions.Item label="理论方量">{Data.quantityOper}m³</Descriptions.Item>
                    <Descriptions.Item label="实际方量">{Data.quantityAct}m³</Descriptions.Item>
                </Descriptions>
            )}
            {Data && (
                <Descriptions size="small" column={2} bordered>
                    <Descriptions.Item label="水胶比(实际⽤量)">{Data.waterBinderRatio}%</Descriptions.Item>
                    <Descriptions.Item label="⽔灰⽐(实际⽤量)">{Data.waterCementRatioAct}%</Descriptions.Item>
                    <Descriptions.Item label="水胶比(理论⽤量)">{Data.waterBinderRatioOper}%</Descriptions.Item>
                    <Descriptions.Item label="⽔灰⽐(理论⽤量)">{Data.waterCementRatioOper}%</Descriptions.Item>
                    <Descriptions.Item label="砂率值">{Data.sandRatio}%</Descriptions.Item>
                </Descriptions>
            )}
            <div className="tips"> 表中数据如无特殊说明,默认单位(Kg) </div>
            <div className="MixingList">
                {TitleList.map((item, index) => (
                    <div key={index}>
                        <div>{item}</div>
                        <div>{OneData[index]}</div>
                        <div>{TwoData[index]}</div>
                    </div>
                ))}
            </div>
            <div className="tips" style={{ color: 'red' }}>
                {' '}
                表中水胶比、水灰比、砂率值仅供参考{' '}
            </div>
        </div>
    )
}

// 沥青拌合站详情
export const LabAsphalt = ({ data }) => {
    const { runAsync } = useRequest(Http, { manual: true })
    const [Data, setData] = useState()
    const [OneData, setOneData] = useState(['实际用量'])
    const [TwoData, setTwoData] = useState(['材料百分比'])
    const [ThrData, setThrData] = useState(['理论配合比'])
    const TitleList = ['材料名称', '⻣料1', '⻣料2', '⻣料3', '⻣料4', '⻣料5', '⻣料6', '矿粉', '⽔泥', '再⽣料']
    useEffect(() => {
        const { url, uuid } = data.data
        runAsync({ url, path: [uuid] }).then(res => {
            const dataOne = [
                '实际用量 (Kg)',
                res.sand1Act,
                res.sand2Act,
                res.gravel1Act,
                res.gravel2Act,
                res.gravel3Act,
                res.gravel4Act,
                res.slagPowderAct,
                res.cement1Act,
                res.recycledMaterialAct,
            ]
            const dataTwo = [
                '材料百分比 (%)',
                res.sand1ActPct,
                res.sand2ActPct,
                res.gravel1ActPct,
                res.gravel2ActPct,
                res.gravel3ActPct,
                res.gravel4ActPct,
                res.slagPowderActPct,
                res.cement1ActPct,
                res.recycleMaterialActPct,
            ]
            const dataThr = [
                '理论配合比 (%)',
                res.sand1Theo,
                res.sand2Theo,
                res.gravel1Theo,
                res.gravel2Theo,
                res.gravel3Theo,
                res.gravel4Theo,
                res.slagPowderTheo,
                res.cement1Theo,
                res.recycleMaterialTheo,
            ]

            setOneData(dataOne)
            setTwoData(dataTwo)
            setThrData(dataThr)
            setData(res)
        })
    }, [data, runAsync])
    return (
        <div className="MixingStations">
            {Data && (
                <Descriptions size="small" layout="vertical" bordered>
                    <Descriptions.Item label="设备编号">{Data.equipmentCode}</Descriptions.Item>
                    <Descriptions.Item label="工程名">{Data.engineeringName}</Descriptions.Item>
                    <Descriptions.Item label="施工地点">{Data.constructionSite}</Descriptions.Item>
                    <Descriptions.Item label="出料时间">{Data.dischargingTime}</Descriptions.Item>
                    <Descriptions.Item label="采集时间">{Data.collectionTime}</Descriptions.Item>
                    <Descriptions.Item label="上传时间">{Data.uploadTime}</Descriptions.Item>
                    <Descriptions.Item label="施工用量">{Data.asphaltAct}Kg</Descriptions.Item>
                    <Descriptions.Item label="油石比">{Data.asphaltAggregateRatioAct}%</Descriptions.Item>
                    <Descriptions.Item label="搅拌时长">{Data.mixingDuration}</Descriptions.Item>
                </Descriptions>
            )}
            {Data && (
                <Descriptions size="small" column={2} bordered>
                    <Descriptions.Item label="油石比(实际配合比)">{Data.asphaltAggregateRatioAct}%</Descriptions.Item>
                    <Descriptions.Item label="沥青(实际⽤量)">{Data.asphaltAct}Kg</Descriptions.Item>
                    <Descriptions.Item label="油石比(理论配合比)">{Data.asphaltAggregateRatioTheo}%</Descriptions.Item>
                    <Descriptions.Item label="沥青(施⼯用量)">{Data.asphaltTheo}Kg</Descriptions.Item>
                </Descriptions>
            )}
            <div className="MixingList">
                {TitleList.map((item, index) => (
                    <div key={index}>
                        <div>{item}</div>
                        <div>{OneData[index] || 0}</div>
                        <div>{TwoData[index] || 0}</div>
                        <div>{ThrData[index] || 0}</div>
                    </div>
                ))}
            </div>
        </div>
    )
}

// 沥青拌合站集配
export const LabAsphaltCentralized = ({ data }) => {
    const [Type] = useState({ 1: '上限', 2: '下限', 3: '理论', 4: '实际' })
    const [Status, { setTrue }] = useBoolean(false)
    const [Data, setData] = useState()

    const { runAsync } = useRequest(Http, {
        manual: true,
        onSuccess: res => {
            const { list } = res
            if (list.length !== 0) {
                const chartsData = list.flatMap(item => {
                    const {
                        curveType,
                        sieve075,
                        sieve15,
                        sieve30,
                        sieve60,
                        sieve118,
                        sieve236,
                        sieve475,
                        sieve950,
                        sieve1320,
                        sieve1600,
                        sieve1900,
                        sieve2650,
                        sieve3150,
                    } = item
                    const data = [
                        { name: Type[curveType], time: '0.075', value: sieve075 },
                        { name: Type[curveType], time: '0.15', value: sieve15 },
                        { name: Type[curveType], time: '0.3', value: sieve30 },
                        { name: Type[curveType], time: '0.6', value: sieve60 },
                        { name: Type[curveType], time: '1.18', value: sieve118 },
                        { name: Type[curveType], time: '2.36', value: sieve236 },
                        { name: Type[curveType], time: '4.75', value: sieve475 },
                        { name: Type[curveType], time: '9.5', value: sieve950 },
                        { name: Type[curveType], time: '13.2', value: sieve1320 },
                        { name: Type[curveType], time: '16', value: sieve1600 },
                        { name: Type[curveType], time: '19', value: sieve1900 },
                        { name: Type[curveType], time: '26.5', value: sieve2650 },
                        { name: Type[curveType], time: '31.5', value: sieve3150 },
                    ]
                    return data
                })
                const config = {
                    data: chartsData,
                    width: 1152,
                    height: 600,
                    autoFit: false,
                    xField: 'time',
                    yField: 'value',
                    seriesField: 'name',
                    color: ['#EDC240', '#AFD8F8', '#CB4B4B', '#4EAB4E'],
                    xAxis: { label: { style: { fill: '#262626', fontSize: 12 } } },
                    yAxis: { label: { style: { fill: '#262626', fontSize: 12 } } },
                }
                setData(config)
                setTrue()
            } else setTrue()
        },
    })

    useEffect(() => {
        runAsync({ url: 'getAsphaltCurveData', data: { dataNumber: data.data.uuid } })
    }, [data, runAsync])

    return (
        <div className="LabAsphaltCentralized">
            {Status ? (
                <div>
                    {Data ? (
                        <div className="Link">{Data && <Line {...Data} />}</div>
                    ) : (
                        <Result status="404" title="暂无集配数据" />
                    )}
                </div>
            ) : (
                <Spin size="large" />
            )}
        </div>
    )
}
// 钢筋保护层
export const LabCoverProtector = ({ data }) => {
    const [ChartsData, setChartsData] = useState()
    const { runAsync } = useRequest(Http, {
        manual: true,
        onSuccess: ({ list }) => {
            if (list.length === 0) return false
            let [{ designThickness, designThickness1, designThickness2, curve }] = list
            let data = curve.split(',').map((item, index) => ({ date: index, 厚度: Number(item) }))
            const config = {
                data,
                width: 1152,
                height: 600,
                autoFit: false,
                color: '#37C8CA',
                xField: 'date',
                yField: '厚度',
                annotations: [
                    {
                        type: 'line',
                        start: ['start', designThickness],
                        end: ['end', designThickness],
                        text: {
                            content: `设计厚度 ${designThickness}`,
                            position: 'right',
                            offsetY: 18,
                            style: { fill: '#7143EA', textAlign: 'right' },
                        },
                        style: { lineDash: [1, 1], stroke: '#7143EA' },
                    },
                    {
                        type: 'line',
                        start: ['start', designThickness1],
                        end: ['end', designThickness1],
                        text: {
                            content: `设计厚度上限 ${designThickness1}`,
                            position: 'right',
                            offsetY: 18,
                            style: { fill: '#5AAAE5', textAlign: 'right' },
                        },
                        style: { lineDash: [2, 2], stroke: '#5AAAE5' },
                    },
                    {
                        type: 'line',
                        start: ['start', designThickness2],
                        end: ['end', designThickness2],
                        text: {
                            content: `设计厚度下限 ${designThickness2}`,
                            position: 'right',
                            offsetY: 18,
                            style: { fill: '#EA8B3B', textAlign: 'right' },
                        },
                        style: { lineDash: [2, 2], stroke: '#EA8B3B' },
                    },
                ],
                xAxis: {
                    title: {
                        text: '点位',
                        position: 'end',
                        offsetX: 0,
                        style: { fill: '#262626', fontSize: 12 },
                    },
                    label: { style: { fill: '#262626', fontSize: 12 } },
                },
                yAxis: {
                    title: {
                        text: '厚度值',
                        position: 'end',
                        spacing: 24,
                        autoRotate: false,
                        style: { fill: '#262626', fontSize: 12 },
                    },
                    label: { style: { fill: '#262626', fontSize: 12 } },
                },
            }
            setChartsData(config)
        },
    })

    useEffect(() => {
        runAsync({ url: 'getLabCoverProtectorGetLabCoverProtectorsList', data: { uuid: data.data.uuid } })
    }, [data, runAsync])

    return <div className="LabCoverProtector">{ChartsData && <Line {...ChartsData} />}</div>
}
// 回弹仪
export const LabReboundHammer = ({ data }) => {
    const [Data, setData] = useState()
    const [DataLength, setDataLength] = useState(1)

    const { runAsync } = useRequest(Http, {
        manual: true,
        onSuccess: ({ list }) => {
            if (list.length !== 0) {
                const [{ reboundData }] = list
                setDataLength(reboundData.split(',').length)
                setData(list)
            }
        },
    })

    useEffect(() => {
        runAsync({ url: 'getLabReboundHammerGetLabReboundHammerAreaNo', data: { uuid: data.data.uuid } })
    }, [data, runAsync])

    const [Title] = useState([
        { uuid: '1', flex: 1, title: '测区' },
        { uuid: '2', title: '回弹值 - Ri' },
        { uuid: '3', flex: 2, title: '构件强度' },
        { uuid: '4', flex: 2, title: '回弹平均值 - Rm' },
        { uuid: '5', flex: 2, title: '碳化深度值 /mm' },
        { uuid: '6', flex: 1, title: '碳化平均值' },
    ])

    const [color] = useState(['#FF2020', '#15ADFF'])

    return (
        <div className="LabReboundHammerModal">
            <div className="Title">
                {DataLength &&
                    Title.map(({ uuid, title, flex }) => {
                        if (uuid === '2') {
                            return (
                                <div key={uuid} style={{ flex: DataLength }}>
                                    <div>{title}</div>
                                    <div>
                                        {[...new Array(DataLength).keys()].map(key => (
                                            <div key={key}>{key + 1}</div>
                                        ))}
                                    </div>
                                </div>
                            )
                        } else {
                            return (
                                <div key={uuid} style={{ flex }}>
                                    {title}
                                </div>
                            )
                        }
                    })}
            </div>
            <div className="List">
                {Data &&
                    Data.map(
                        ({
                            areaNo,
                            carbonizationAvg,
                            carbonationDepthofcomponents,
                            componentStrength,
                            reboundData,
                            reboundAvg,
                        }) => (
                            <div key={areaNo}>
                                <div style={{ flex: Title[0].flex }}> {areaNo} </div>
                                <div style={{ flex: DataLength }}>
                                    {(() => {
                                        const arr = reboundData.split(',')
                                        const orj = arr.map((item, index) => ({ number: index, value: item }))
                                        orj.sort((a, b) => a.value.localeCompare(b.value))
                                        const smallArr = [orj.at(1).number, orj.at(2).number, orj.at(3).number]
                                        const bigArr = [orj.at(-1).number, orj.at(-2).number, orj.at(-3).number]
                                        return arr.map((item, index) => (
                                            <div
                                                key={index}
                                                style={{
                                                    color:
                                                        bigArr.indexOf(index) !== -1
                                                            ? color[0]
                                                            : smallArr.indexOf(index) !== -1
                                                            ? color[1]
                                                            : ''
                                                            ? '#f8f8f8'
                                                            : '#262626',
                                                    fontWeight:
                                                        bigArr.indexOf(index) !== -1 || smallArr.indexOf(index) !== -1
                                                            ? '900'
                                                            : '100',
                                                }}
                                            >
                                                {item}
                                            </div>
                                        ))
                                    })()}
                                </div>
                                <div style={{ flex: Title[2].flex }}>{componentStrength}</div>
                                <div style={{ flex: Title[3].flex }}>{reboundAvg}</div>
                                <div style={{ flex: Title[4].flex }}>{carbonizationAvg}</div>
                                <div style={{ flex: Title[5].flex }}>{carbonationDepthofcomponents}</div>
                            </div>
                        ),
                    )}
            </div>
            <div className="tip">
                <div>
                    * <span style={{ color: color[0] }}>红色</span>高亮为最大值,
                    <span style={{ color: color[1] }}>蓝色</span>高亮为最小值
                </div>
                <div>* 回弹值除去三个最大值和三个最小值后计算出回弹平均值</div>
            </div>
        </div>
    )
}

// 一、来样登记
export const SampleA01 = ({ data }) => {
    const { header, record, Permission } = data
    const actionRef = useRef()
    const [CData, setCData] = useState()
    const headers = { Authorization: sessionStorage.getItem('TOKEN') }
    const [activeKey, setActiveKey] = useState('tab1')
    const OptionsEvent = useEventEmitter()
    OptionsEvent.useSubscription(val => setOptionsCall(val))
    useMount(async () => setCData(await LabReportTemplates()))
    const DataList = {
        tab1: () => ({
            hideInSearch: true,
            pageSize: 10,
            params: {},
            get: API_LIST([record.uuid])['getSampleAttachments'],
            added: 'posSampleAttachments',
            initialValues: { uuid: record.uuid, sampleUuid: record.uuid },
            columns: [
                {
                    dataIndex: 'uuid',
                    title: 'uuid',
                    valueType: 'hidden',
                    hideInTable: true,
                },
                {
                    dataIndex: 'sampleUuid',
                    title: 'sampleUuid',
                    valueType: 'hidden',
                    hideInTable: true,
                },
                {
                    title: '附件名称',
                    dataIndex: 'tableName',
                    search: false,
                    type: 'hidden',
                    hideInAdded: true,
                    hideInModify: true,
                    render: (_, { attachment }) => <div>{attachment?.originalName}</div>,
                },
                {
                    dataIndex: 'attachmentUuid',
                    title: '样品附件',
                    valueType: 'upload',
                    valueFile: [1],
                    fileUrl: 'fileUrl',
                    rules: true,
                    hideInTable: true,
                },
                {
                    dataIndex: 'fileUrl',
                    title: '样品附件',
                    valueType: 'hidden',
                    hideInSearch: true,
                    hideInTable: true,
                    hideInAdded: true,
                    hideInModify: true,
                    width: 400,
                },
                {
                    title: '操作',
                    valueType: 'systemOperation',
                    fixed: 'right',
                    width: 200,
                    hideInSearch: true,
                    hideInAdded: true,
                    hideInModify: true,
                    render: (_, record) => {
                        const { uuid, attachment } = record
                        return [
                            Permission.findIndex(v => v.uuid === '13e81b48-8556-4aee-9fc3-c19bd8d9c519') !== -1 &&
                                attachment?.fileUrl && (
                                    <AnnexButton
                                        OptionsEvent={OptionsEvent}
                                        key="see"
                                        url={attachment.fileUrl}
                                        title="查看附件"
                                    />
                                ),
                            Permission.findIndex(v => v.uuid === '50a0c2e3-97fd-4307-9e52-0daf3085d6d7') !== -1 && (
                                <DelDataButton
                                    OptionsEvent={OptionsEvent}
                                    key="del"
                                    title="删除"
                                    url="SampleAttachments"
                                    uuid={uuid}
                                />
                            ),
                        ]
                    },
                },
            ],
        }),
        tab2: pdata => {
            return {
                hideInSearch: true,
                pageSize: 10,
                params: { pageIndex: 1, sampleUuid: record.uuid },
                get: API_LIST([record.uuid])['getSampleItem'],
                added: 'posSampleItemAddSampleItem',
                modify: 'posSampleItemUpdateSampleItem',
                initialValues: { sampleUuid: record.uuid },
                columns: [
                    commonTableList.uuid,
                    {
                        dataIndex: 'sampleUuid',
                        title: '样品编号',
                        valueType: 'hidden',
                        hideInTable: true,
                        hideInSearch: true,
                        width: 150,
                    },
                    {
                        dataIndex: 'displayNo',
                        title: '样品编号',
                        valueType: 'hidden',
                        hideInSearch: true,
                        hideInAdded: true,
                        hideInModify: true,
                        width: 200,
                    },
                    {
                        dataIndex: 'serialNo',
                        title: '报告编号',
                        valueType: 'hidden',
                        hideInSearch: true,
                        hideInAdded: true,
                        hideInModify: true,
                        width: 200,
                    },
                    {
                        dataIndex: 'labReportTemplateUuid',
                        title: '报告名称',
                        valueType: 'select',
                        valueEnum: pdata?.LabReportEnum,
                        rules: true,
                        hideInSearch: true,
                        hideInModify: true,
                        width: 200,
                    },
                    {
                        dataIndex: 'selectedTestTypeUuid',
                        title: '报告参数',
                        valueJudge: 'labReportTemplateUuid',
                        JudgeValue: '',
                        valueType: 'selectMultiple',
                        fieldNames: { label: 'tableName', value: 'trueUuid' },
                        multiple: true,
                        valueEnum: pdata?.LabReportData,
                        rules: true,
                        hideInTable: true,
                        hideInModify: true,
                    },
                    {
                        dataIndex: 'selectedTestTypeNames',
                        title: '检测参数',
                        type: 'hidden',

                        hideInSearch: true,
                        hideInAdded: true,
                        hideInModify: true,
                        width: 300,
                    },
                    {
                        dataIndex: 'tableName',
                        title: '样品名称',
                        valueType: 'input',
                        rules: true,
                        width: 200,
                    },
                    {
                        dataIndex: 'spec',
                        title: '规格型号',
                        valueType: 'input',
                        hideInSearch: true,
                        width: 100,
                    },
                    {
                        dataIndex: 'num',
                        title: '数量',
                        valueType: 'inputNumber',
                        rules: true,
                        hideInSearch: true,
                        width: 100,
                    },
                    {
                        dataIndex: 'unit',
                        title: '单位',
                        valueType: 'input',
                        hideInSearch: true,
                        rules: true,
                        width: 100,
                    },

                    {
                        dataIndex: 'testPieceNum',
                        title: '试件数量',
                        valueType: 'input',
                        hideInSearch: true,
                        rules: true,
                        width: 100,
                    },

                    {
                        dataIndex: 'sampleDisposal',
                        title: '样品处置',
                        valueType: 'input',
                        hideInSearch: true,
                        width: 100,
                    },
                    {
                        dataIndex: 'factoryName',
                        title: '厂家名称',
                        valueType: 'input',
                        hideInSearch: true,
                        width: 300,
                    },
                    {
                        dataIndex: 'factorySerialNo',
                        title: '出厂编号',
                        valueType: 'input',
                        hideInSearch: true,
                        width: 200,
                    },
                    {
                        dataIndex: 'standardModifyNo',
                        title: '报告唯一性标识',
                        valueType: 'input',
                        width: 200,
                    },
                    {
                        dataIndex: 'factoryDate',
                        title: '出厂日期',
                        valueType: 'Date',
                        hideInSearch: true,
                        showTime: true,
                        width: 200,
                    },
                    {
                        title: '操作',
                        valueType: 'systemOperation',
                        fixed: 'right',
                        width: 300,
                        hideInSearch: true,
                        hideInAdded: true,
                        hideInModify: true,
                        render: (_, record) => {
                            const { uuid, labReportTemplateTableName } = record
                            return [
                                <ModDataButton OptionsEvent={OptionsEvent} key="modify" title="修改" data={record} />,
                                Permission.findIndex(v => v.uuid === '4335a6b4-70bf-4bdc-9c5e-dbba6f7fe493') !== -1 && (
                                    <CommonButton
                                        key="qrcode"
                                        OptionsEvent={OptionsEvent}
                                        title="二维码"
                                        data={{
                                            type: 'PrintQRcodeList',
                                            smallTitle: labReportTemplateTableName + ' 二维码',
                                            record,
                                            width: 800,
                                        }}
                                    />

                                    // <PrintQRCodeButton
                                    //     OptionsEvent={OptionsEvent}
                                    //     key="qrcode"
                                    //     title="二维码"
                                    //     url="SampleParameter"
                                    //     data={record}
                                    // />
                                ),
                                Permission.findIndex(v => v.uuid === '3d9d5e9d-1140-42ca-b0ea-0a9b2acc823d') !== -1 && (
                                    <SaveExcelButton
                                        key="excel"
                                        title="下载报告"
                                        api={API_LIST()['getLabReport']}
                                        data={{ SampleItemUuid: uuid }}
                                    />
                                ),
                                Permission.findIndex(v => v.uuid === '1a1b7743-1ef2-49e9-bdea-f1a990f35f30') !== -1 && (
                                    <DelDataButton
                                        OptionsEvent={OptionsEvent}
                                        key="del"
                                        title="删除"
                                        url="SampleItem"
                                        uuid={uuid}
                                    />
                                ),
                            ]
                        },
                    },
                ],
            }
        },
    }
    const [OptionsCall, setOptionsCall] = useState()
    const [Parmas, setParmas] = useState({ active: 'tab1' })
    const { runAsync } = useRequest(Http, { manual: true })
    const onSubmit = () => {
        runAsync({ url: 'posSampleAddSampleFlowRecord', data: { status: 0, sampleUuid: record.uuid } }).then(() =>
            message.success('完成来样登记'),
        )
    }

    const [IndexNumber, setIndexNumber] = useState(1)
    const [SizeNumber, setSizeNumber] = useState(Parmas.pageSize || 10)

    if (CData) {
        return (
            <div className="SampleModel SampleA01">
                <DescriptionsModal data={record} pageHeaderData={header} />
                <div className="Tables">
                    <ProTable
                        actionRef={actionRef}
                        columns={DataList[activeKey](CData).columns}
                        params={Parmas}
                        request={async (params = {}) => {
                            delete params.current
                            params.pageIndex = IndexNumber ?? 1
                            params.pageSize = SizeNumber ?? 10
                            params.sampleUuid = record.uuid
                            return request(DataList[activeKey]().get, { params, headers }).then(data => {
                                if (data.list) return { data: data.list, total: data.total, success: true }
                                else return { data, success: true }
                            })
                        }}
                        pagination={{
                            pageSize: SizeNumber,
                            showSizeChanger: true,
                            onChange: (e, a) => {
                                setIndexNumber(e)
                                setSizeNumber(a)
                            },
                        }}
                        columnsState={{ persistenceKey: 'pro-table-singe-demos', persistenceType: 'localStorage' }}
                        rowKey="uuid"
                        toolbar={{
                            menu: {
                                type: 'tab',
                                activeKey,
                                items: [
                                    { key: 'tab1', label: '样品图片' },
                                    { key: 'tab2', label: '配置检测参数' },
                                ],
                                onChange: key => {
                                    actionRef.current.reload()
                                    setActiveKey(key)
                                    setParmas({
                                        active: key,
                                        pageIndex: 1,
                                        pageSize: 10,
                                    })
                                },
                            },
                            actions: [
                                Permission.findIndex(v => v.uuid === 'b519822b-0c17-43ef-9dda-63e54349d973') !== -1 &&
                                    activeKey === 'tab1' && (
                                        <AddDataButton
                                            OptionsEvent={OptionsEvent}
                                            type="primary"
                                            icon="add"
                                            title="新增来样附件"
                                        />
                                    ),
                                Permission.findIndex(v => v.uuid === 'cf4df164-1b03-4c5e-b0bc-145c26d49804') !== -1 &&
                                    activeKey === 'tab2' && (
                                        <AddDataButton
                                            OptionsEvent={OptionsEvent}
                                            type="primary"
                                            icon="add"
                                            title="新增配置参数"
                                        />
                                    ),
                                Permission.findIndex(v => v.uuid === 'f4892470-7210-457a-b585-10ba3dc46886') !== -1 && (
                                    <Button
                                        key="primary"
                                        type="primary"
                                        onClick={() => ExportExcel(API_LIST()['getLabPowerAttorney'], record)}
                                    >
                                        下载委托书
                                    </Button>
                                ),
                            ],
                        }}
                        search={false}
                        scroll={{ x: 800, y: 400 }}
                    />
                </div>
                <div className="Submit">
                    {Permission.findIndex(v => v.uuid === '313db190-ba48-42ed-ba7c-79912dfdcb33') !== -1 && (
                        <Button type="primary" onClick={onSubmit}>
                            完成来样登记
                        </Button>
                    )}
                </div>
                <ModalBox OptionsCall={OptionsCall} actionRef={actionRef} configure={DataList[activeKey](CData)} />
            </div>
        )
    }
}
// 二、分配任务
export const SampleA02 = ({ data }) => {
    const { header, record, Permission, actionRef } = data
    const { runAsync: getOptions } = useRequest(Http, { manual: true })
    const { runAsync: putPerson } = useRequest(Http, { manual: true })
    const { runAsync: posSubmit } = useRequest(Http, { manual: true })
    const [options, setOptions] = useState([])
    useMount(() => {
        getOptions({ url: 'getOrganization' }).then(res => setOptions(res.list))
    })
    const [Value, setValue] = useState({
        organizationUuid: record.organizationUuid,
        sampleReceiver: record.sampleReceiver,
    })
    const onPut = () => {
        putPerson({ url: 'putSample', data: { ...record, ...Value }, path: [record.uuid] }).then(() => {
            actionRef.current.reload()
            message.success('完成分配任务')
        })
    }
    const onSubmit = () => {
        posSubmit({ url: 'posSampleAddSampleFlowRecord', data: { status: 1, sampleUuid: record.uuid } }).then(() =>
            message.success('人员分配已完成'),
        )
    }
    return (
        <div className="SampleModel SampleA02">
            <DescriptionsModal data={record} pageHeaderData={header} />
            {Permission.findIndex(v => v.uuid === 'dd255014-6572-4752-9c4e-88b3f79750d0') !== -1 && (
                <div className="Tables">
                    <div className="Label">
                        <div>试验科室 : </div>
                        <Select
                            defaultValue={record.organizationUuid}
                            options={options}
                            placeholder="请选择试验科室"
                            fieldNames={{ value: 'uuid', label: 'tableName' }}
                            onChange={e => setValue(data => ({ ...data, organizationUuid: e }))}
                        />
                    </div>
                    <div className="Label">
                        <div>试验人员 : </div>
                        <Input
                            defaultValue={record.sampleReceiver}
                            placeholder="请填写试验人员"
                            onChange={e => setValue(data => ({ ...data, sampleReceiver: e.target.value }))}
                        />
                    </div>

                    <div className="Submit">
                        <Button type="primary" onClick={onPut}>
                            保存人员
                        </Button>
                    </div>
                </div>
            )}
            {Permission.findIndex(v => v.uuid === '4b939a45-c923-41eb-bb62-1227565f203f') !== -1 && (
                <div className="Submit">
                    <Button type="primary" onClick={onSubmit}>
                        完成分配任务
                    </Button>
                </div>
            )}
        </div>
    )
}
// 三、领样品
export const SampleA03 = ({ data }) => {
    const { header, record, Permission } = data
    const actionRef = useRef()
    const [OptionsCall, setOptionsCall] = useState()
    const OptionsEvent = useEventEmitter()
    OptionsEvent.useSubscription(val => setOptionsCall(val))
    const DataList = {
        get: API_LIST()['getSampleReportAttachment'],
        added: 'posSampleReportAttachment',
        initialValues: { sampleUuid: record.uuid, tableName: 0 },
        columns: [
            {
                dataIndex: 'sampleUuid',
                title: 'SampleUuid',
                valueType: 'hidden',
                hideInSearch: true,
                hideInTable: true,
            },
            {
                dataIndex: 'tableName',
                title: 'tableName',
                valueType: 'hidden',
                hideInSearch: true,
                hideInTable: true,
            },
            {
                dataIndex: 'originalName',
                title: '名称',
                valueType: 'hidden',
                search: false,
                hideInAdded: true,
                hideInModify: true,
            },
            {
                dataIndex: 'createUserName',
                title: '上传人',
                valueType: 'hidden',
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
            },
            {
                dataIndex: 'createTime',
                title: '上传时间',
                valueType: 'hidden',
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
            },
            {
                dataIndex: 'attachmentUuid',
                title: '样品报告附件',
                valueType: 'upload',
                valueFile: [1, 2, 3, 4, 5],
                fileUrl: 'fileUrl',
                rules: true,
                hideInTable: true,
            },
            {
                dataIndex: 'fileUrl',
                title: '样品附件',
                valueType: 'hidden',
                hideInSearch: true,
                hideInTable: true,
                hideInAdded: true,
                hideInModify: true,
                width: 400,
            },
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 200,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { uuid, fileUrl } = record
                    return [
                        Permission.findIndex(v => v.uuid === '74e43e9f-f139-45d5-a417-890ca32dcb82') !== -1 &&
                            fileUrl && (
                                <AnnexButton OptionsEvent={OptionsEvent} key="see" url={fileUrl} title="查看附件" />
                            ),
                        Permission.findIndex(v => v.uuid === '161dcec3-87ef-4829-ae3d-0c06b7a170ef') !== -1 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url="SampleReportAttachment"
                                uuid={uuid}
                            />
                        ),
                    ]
                },
            },
        ],
    }

    const headers = { Authorization: sessionStorage.getItem('TOKEN') }
    const [Parmas, setParmas] = useState({ pageIndex: 1, pageSize: 10, tableName: 0 })

    const { runAsync } = useRequest(Http, { manual: true })
    const onSubmit = () => {
        runAsync({ url: 'posSampleAddSampleFlowRecord', data: { status: 2, sampleUuid: record.uuid } }).then(() =>
            message.success('完成领样品'),
        )
    }

    const [IndexNumber, setIndexNumber] = useState(1)
    const [SizeNumber, setSizeNumber] = useState(Parmas.pageSize || 10)

    return (
        <div className="SampleModel SampleA03">
            <DescriptionsModal data={record} pageHeaderData={header} type="Sample" />
            <div className="Tables">
                <ProTable
                    actionRef={actionRef}
                    columns={DataList.columns}
                    params={Parmas}
                    request={async (params = {}) => {
                        delete params.current
                        params.pageIndex = IndexNumber ?? 1
                        params.pageSize = SizeNumber ?? 10
                        params.sampleUuid = record.uuid
                        return request(DataList.get, { params, headers }).then(data => {
                            if (data.list) return { data: data.list, total: data.total, success: true }
                            else return { data, success: true }
                        })
                    }}
                    pagination={{
                        pageSize: SizeNumber,
                        showSizeChanger: true,
                        onChange: (e, a) => {
                            setIndexNumber(e)
                            setSizeNumber(a)
                        },
                    }}
                    columnsState={{ persistenceKey: 'pro-table-singe-demos', persistenceType: 'localStorage' }}
                    rowKey="uuid"
                    toolbar={{
                        actions: [
                            Permission.findIndex(v => v.uuid === 'be3644c9-0431-4847-b19f-2fac1864a0ba') !== -1 && (
                                <Button
                                    key="primary"
                                    type="primary"
                                    onClick={() => ExportExcel(API_LIST()['getLabAssignmentBook'], record)}
                                >
                                    下载任务单
                                </Button>
                            ),
                            Permission.findIndex(v => v.uuid === '480ba668-33f5-4e64-b479-20b82d9f83a1') !== -1 && (
                                <AddDataButton
                                    OptionsEvent={OptionsEvent}
                                    type="primary"
                                    icon="add"
                                    title="上传任务单照片"
                                />
                            ),
                        ],
                    }}
                    search={false}
                    scroll={{ x: 800, y: 400 }}
                />
            </div>
            <div className="Submit">
                {Permission.findIndex(v => v.uuid === '27325052-a619-46d7-9eb6-3b08e4d4dca2') !== -1 && (
                    <Button type="primary" onClick={onSubmit}>
                        完成领样品
                    </Button>
                )}
            </div>
            <ModalBox OptionsCall={OptionsCall} actionRef={actionRef} configure={DataList} />
        </div>
    )
}

export const SampleApprovalRemark = ({ data, Off }) => {
    const { uuid, actionRef, title } = data
    const TypeList = {
        初审: {
            pos: 'posSampleItemAddFirstApproval',
            data: { uuid, firstApprovalStatus: null, firstApprovalRemark: null },
        },
        终审: {
            pos: 'posSampleItemAddLastApproval',
            data: { uuid, lastApprovalStatus: null, lastApprovalRemark: null },
        },
    }

    const [Value, setValue] = useState(TypeList[title].data)
    const { runAsync } = useRequest(Http, { manual: true })
    const onSubmit = () => {
        runAsync({ url: TypeList[title].pos, data: Value }).then(() => {
            actionRef.current.reload()
            Off()
        })
    }

    return (
        <div className="SampleApprovalRemark">
            <div className="Label">
                <div>审核状态 : </div>
                <Select
                    options={[
                        { label: '未通过', value: 0 },
                        { label: '通过', value: 1 },
                    ]}
                    onChange={e =>
                        setValue(data => {
                            if (title === '初审') return { ...data, firstApprovalStatus: e }
                            else return { ...data, lastApprovalStatus: e }
                        })
                    }
                />
            </div>
            <div className="Label">
                <div>审核意见 : </div>
                <TextArea
                    autoSize
                    onChange={e =>
                        setValue(data => {
                            if (title === '初审') return { ...data, firstApprovalRemark: e.target.value }
                            else return { ...data, lastApprovalRemark: e.target.value }
                        })
                    }
                />
            </div>
            <div className="Submit">
                <Button type="primary" onClick={onSubmit}>
                    提交审核
                </Button>
            </div>
        </div>
    )
}

// 四、样品检测
export const SampleA04 = ({ data }) => {
    const { header, record, Permission } = data
    console.log(Permission)
    const actionRef = useRef()
    const [OptionsCall, setOptionsCall] = useState()
    const [Parmas, setParmas] = useState({ pageIndex: 1, pageSize: 10 })
    const headers = { Authorization: sessionStorage.getItem('TOKEN') }
    const [CData, setCData] = useState()
    useMount(async () => {
        setCData(await LabReportTemplates())
    })
    const OptionsEvent = useEventEmitter()
    OptionsEvent.useSubscription(val => setOptionsCall(val))

    const DataList = {
        hideInSearch: true,
        pageSize: 10,
        params: { sampleUuid: record.uuid },
        get: API_LIST([record.uuid])['getSampleItem'],
        columns: data => [
            commonTableList.uuid,
            {
                dataIndex: 'sampleUuid',
                title: '样品编号',
                type: 'hidden',
                hideInTable: true,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                width: 150,
            },
            {
                dataIndex: 'displayNo',
                title: '样品编号',
                type: 'hidden',
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                width: 150,
            },
            {
                dataIndex: 'serialNo',
                title: '报告编号',
                type: 'hidden',
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                width: 150,
            },
            {
                dataIndex: 'labReportTemplateUuid',
                title: '报告名称',
                valueType: 'select',
                valueEnum: data.LabReportEnum,
                rules: true,
                hideInSearch: true,
                width: 200,
            },
            {
                dataIndex: 'selectedTestTypes',
                title: '检测参数',
                type: 'hidden',
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                width: 600,
                render: (_, res) => {
                    const { selectedTestTypes, labReportTemplateUuid, uuid: SampleItemUuid } = res
                    return (
                        <div>
                            {selectedTestTypes.map(({ uuid, tableName, labDataSourceUuid }) => {
                                if (
                                    Permission.findIndex(v => v.uuid === '57f6ad89-bf17-44c7-835d-659c01d96f82') !==
                                        -1 &&
                                    labDataSourceUuid === '7ffd2f4f-e3e7-4a44-ba0f-561781fb9de5'
                                ) {
                                    return (
                                        <OpenExcelButton
                                            key={uuid}
                                            title={tableName}
                                            OptionsEvent={OptionsEvent}
                                            data={{
                                                save: true,
                                                submit: true,
                                                SampleItemUuid,
                                                TestTypeUuid: uuid,
                                                url: 'getSampleItemGetTestDataEXCEL',
                                                pos: 'posSampleItemUploadTestDataEXCEL',
                                                LabReportTemplatesUuid: labReportTemplateUuid,
                                            }}
                                        />
                                    )
                                } else return false
                            })}
                        </div>
                    )
                },
            },
            {
                dataIndex: 'tableName',
                title: '样品名称',
                valueType: 'input',
                rules: true,
                width: 150,
            },
            {
                dataIndex: 'spec',
                title: '规格型号',
                valueType: 'input',
                hideInSearch: true,
                width: 100,
            },
            {
                dataIndex: 'num',
                title: '数量',
                valueType: 'inputNumber',
                rules: true,
                hideInSearch: true,
                width: 100,
            },
            {
                dataIndex: 'unit',
                title: '单位',
                valueType: 'input',
                hideInSearch: true,
                rules: true,
                width: 80,
            },
            {
                dataIndex: 'firstApprovalStatus',
                title: '初审状态',
                valueType: 'select',
                valueEnum: { 0: '不通过', 1: '通过' },
                rules: true,
                width: 80,
                hideInAdded: true,
                hideInModify: true,
                hideInSearch: true,
            },
            {
                dataIndex: 'firstApprovalRemark',
                title: '初审意见',
                valueType: 'input',
                rules: true,
                width: 200,
                hideInAdded: true,
                hideInModify: true,
                hideInSearch: true,
            },
            {
                dataIndex: 'firstApprovalUserName',
                title: '初审人',
                valueType: 'input',
                rules: true,
                width: 200,
                hideInAdded: true,
                hideInModify: true,
                hideInSearch: true,
            },
            {
                dataIndex: 'firstApprovalTime',
                title: '初审日期',
                valueType: 'input',
                rules: true,
                width: 200,
                hideInAdded: true,
                hideInModify: true,
                hideInSearch: true,
            },
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 240,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { attachmentUuid, attachment } = record
                    return [
                        // Permission.findIndex(v => v.uuid === 'a3b1ee8e-df94-4910-b2ad-b0f52a82266c') !== -1 && (
                        //     <SaveExcelButton
                        //         key="excel"
                        //         title="下载Word报告"
                        //         api={API_LIST()['getLabReport']}
                        //         data={{ SampleItemUuid: uuid }}
                        //     />
                        // ),

                        Permission.findIndex(v => v.uuid === 'cf40cc50-3a6f-4abe-8781-f78eaedec345') !== -1 &&
                            attachmentUuid &&
                            attachment?.fileUrl && (
                                <AnnexButton
                                    OptionsEvent={OptionsEvent}
                                    key="see"
                                    url={attachment.fileUrl}
                                    title="查看PDF报告"
                                />
                            ),
                        Permission.findIndex(v => v.uuid === 'b2082070-b0bc-4112-b66c-9df7815adef3') !== -1 && (
                            <Button
                                key="app"
                                type="link"
                                onClick={() =>
                                    setOptionsCall({
                                        type: 'SampleApprovalRemark',
                                        data: { title: '初审', uuid: record.uuid, actionRef },
                                    })
                                }
                            >
                                初审
                            </Button>
                        ),
                    ]
                },
            },
        ],
    }

    const { runAsync } = useRequest(Http, { manual: true })
    const onSubmit = () => {
        runAsync({ url: 'posSampleAddSampleFlowRecord', data: { status: 3, sampleUuid: record.uuid } }).then(() =>
            message.success('完成样品检测'),
        )
    }

    const [IndexNumber, setIndexNumber] = useState(1)
    const [SizeNumber, setSizeNumber] = useState(Parmas.pageSize || 10)

    if (CData) {
        return (
            <div className="SampleModel SampleA04">
                <DescriptionsModal data={record} pageHeaderData={header} type="Sample" />
                <div className="Tables">
                    <ProTable
                        actionRef={actionRef}
                        columns={DataList.columns(CData)}
                        params={Parmas}
                        request={async (params = {}) => {
                            delete params.current
                            params.pageIndex = IndexNumber ?? 1
                            params.pageSize = SizeNumber ?? 10
                            params.sampleUuid = record.uuid
                            return request(DataList.get, { params, headers }).then(data => {
                                if (data.list) return { data: data.list, total: data.total, success: true }
                                else return { data, success: true }
                            })
                        }}
                        pagination={{
                            pageSize: SizeNumber,
                            showSizeChanger: true,
                            onChange: (e, a) => {
                                setIndexNumber(e)
                                setSizeNumber(a)
                            },
                        }}
                        columnsState={{ persistenceKey: 'pro-table-singe-demos', persistenceType: 'localStorage' }}
                        rowKey="uuid"
                        search={false}
                        scroll={{ x: 800, y: 400 }}
                    />
                </div>
                <div className="Submit">
                    {Permission.findIndex(v => v.uuid === 'f1927fff-6bc8-41c0-9ce6-fe6ae4a88414') !== -1 && (
                        <Button type="primary" onClick={onSubmit}>
                            完成样品检测
                        </Button>
                    )}
                </div>
                <ModalBox OptionsCall={OptionsCall} actionRef={actionRef} />
            </div>
        )
    }
}
// 五、审核报告
export const SampleA05 = ({ data }) => {
    const { header, record, Permission } = data
    const actionRef = useRef()
    const [OptionsCall, setOptionsCall] = useState()
    const [Parmas, setParmas] = useState({ pageIndex: 1, pageSize: 10 })
    const headers = { Authorization: sessionStorage.getItem('TOKEN') }
    const [CData, setCData] = useState()
    useMount(async () => {
        setCData(await LabReportTemplates())
    })
    const OptionsEvent = useEventEmitter()
    OptionsEvent.useSubscription(val => setOptionsCall(val))
    const { runAsync: delAnnex } = useRequest(Http, { manual: true })
    const onDelete = uuid => {
        delAnnex({ url: 'posSampleItemDelSampleItemAttachment', path: [uuid] }).then(() => actionRef.current.reload())
    }

    const DataList = {
        hideInSearch: true,
        pageSize: 10,
        params: { sampleUuid: record.uuid },
        get: API_LIST([record.uuid])['getSampleItem'],
        columns: data => [
            commonTableList.uuid,
            {
                dataIndex: 'sampleUuid',
                title: '样品编号',
                type: 'hidden',
                hideInTable: true,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                width: 150,
            },
            {
                dataIndex: 'displayNo',
                title: '样品编号',
                type: 'hidden',
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                width: 150,
            },
            {
                dataIndex: 'serialNo',
                title: '报告编号',
                type: 'hidden',
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                width: 150,
            },
            {
                dataIndex: 'labReportTemplateUuid',
                title: '报告名称',
                valueType: 'select',
                valueEnum: data.LabReportEnum,
                rules: true,
                hideInSearch: true,
                width: 200,
            },
            // {
            //     dataIndex: 'selectedTestTypes',
            //     title: '检测参数',
            //     type: 'hidden',
            //     hideInSearch: true,
            //     hideInAdded: true,
            //     hideInModify: true,
            //     width: 600,
            //     render: (_, res) => {
            //         const { selectedTestTypes, labReportTemplateUuid, uuid: SampleItemUuid } = res
            //         return (
            //             <div>
            //                 {selectedTestTypes.map(({ uuid, tableName, labDataSourceUuid }) => {
            //                     if (
            //                         Permission.findIndex(v => v.uuid === '9d4c03e9-0a29-432d-b06b-a8569ce70726') !==
            //                         -1 &&
            //                         labDataSourceUuid === '7ffd2f4f-e3e7-4a44-ba0f-561781fb9de5'
            //                     ) {
            //                         return (
            //                             <OpenExcelButton
            //                                 key={uuid}
            //                                 title={tableName}
            //                                 OptionsEvent={OptionsEvent}
            //                                 data={{
            //                                     save: true,
            //                                     submit: true,
            //                                     SampleItemUuid,
            //                                     TestTypeUuid: uuid,
            //                                     url: 'getSampleItemGetTestDataEXCEL',
            //                                     pos: 'posSampleItemUploadTestDataEXCEL',
            //                                     LabReportTemplatesUuid: labReportTemplateUuid,
            //                                 }}
            //                             />
            //                         )
            //                     } else return false
            //                 })}
            //             </div>
            //         )
            //     },
            // },
            {
                dataIndex: 'tableName',
                title: '样品名称',
                valueType: 'input',
                rules: true,
                width: 150,
            },
            {
                dataIndex: 'spec',
                title: '规格型号',
                valueType: 'input',
                hideInSearch: true,
                width: 100,
            },
            {
                dataIndex: 'num',
                title: '数量',
                valueType: 'inputNumber',
                rules: true,
                hideInSearch: true,
                width: 100,
            },
            {
                dataIndex: 'unit',
                title: '单位',
                valueType: 'input',
                hideInSearch: true,
                rules: true,
                width: 80,
            },
            {
                dataIndex: 'firstApprovalStatus',
                title: '初审状态',
                valueType: 'select',
                valueEnum: { 0: '不通过', 1: '通过' },
                rules: true,
                width: 80,
                hideInAdded: true,
                hideInModify: true,
                hideInSearch: true,
            },
            {
                dataIndex: 'firstApprovalRemark',
                title: '初审意见',
                valueType: 'input',
                rules: true,
                width: 200,
                hideInAdded: true,
                hideInModify: true,
                hideInSearch: true,
            },
            {
                dataIndex: 'firstApprovalUserName',
                title: '初审人',
                valueType: 'input',
                rules: true,
                width: 200,
                hideInAdded: true,
                hideInModify: true,
                hideInSearch: true,
            },
            {
                dataIndex: 'firstApprovalTime',
                title: '初审日期',
                valueType: 'input',
                rules: true,
                width: 200,
                hideInAdded: true,
                hideInModify: true,
                hideInSearch: true,
            },
            {
                dataIndex: 'lastApprovalStatus',
                title: '终审状态',
                valueType: 'select',
                valueEnum: { 0: '不通过', 1: '通过' },
                rules: true,
                width: 80,
                hideInAdded: true,
                hideInModify: true,
                hideInSearch: true,
            },
            {
                dataIndex: 'lastApprovalRemark',
                title: '终审意见',
                valueType: 'input',
                rules: true,
                width: 200,
                hideInAdded: true,
                hideInModify: true,
                hideInSearch: true,
            },
            {
                dataIndex: 'lastApprovalUserName',
                title: '终审人',
                valueType: 'input',
                rules: true,
                width: 200,
                hideInAdded: true,
                hideInModify: true,
                hideInSearch: true,
            },
            {
                dataIndex: 'lastApprovalTime',
                title: '终审日期',
                valueType: 'input',
                rules: true,
                width: 200,
                hideInAdded: true,
                hideInModify: true,
                hideInSearch: true,
            },
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 400,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { uuid, attachmentUuid, attachment } = record
                    return [
                        Permission.findIndex(v => v.uuid === '11e1212c-175c-4d55-ade9-2674eda15386') !== -1 && (
                            <SaveExcelButton
                                key="excel"
                                title="下载Word报告"
                                api={API_LIST()['getLabReport']}
                                data={{ SampleItemUuid: record.uuid }}
                            />
                        ),
                        Permission.findIndex(v => v.uuid === 'c7c700eb-616a-4ed7-ae68-c19cc1f6ab35') !== -1 &&
                            !attachmentUuid && (
                                <AddDataButton
                                    key="add1"
                                    OptionsEvent={OptionsEvent}
                                    type="link"
                                    title="上传PDF报告"
                                    Adduuid={{ sampleItemUuid: uuid }}
                                />
                            ),
                        Permission.findIndex(v => v.uuid === '540a2e4f-afb2-4aec-b3a1-66a094edefe0') !== -1 &&
                            attachmentUuid &&
                            attachment?.fileUrl(
                                <AnnexButton
                                    OptionsEvent={OptionsEvent}
                                    key="see"
                                    url={attachment.fileUrl}
                                    title="查看PDF报告"
                                />,
                            ),
                        Permission.findIndex(v => v.uuid === '8c30e998-f47c-4e38-a792-ad5a9119ad1e') !== -1 &&
                            attachmentUuid && (
                                <Button key="del" type="link" danger onClick={() => onDelete(attachmentUuid)}>
                                    删除PDF报告
                                </Button>
                            ),
                        Permission.findIndex(v => v.uuid === '489c911f-1ec5-4dab-919a-85ba4a49522b') !== -1 && (
                            <Button
                                key="app"
                                type="link"
                                onClick={() =>
                                    setOptionsCall({
                                        type: 'SampleApprovalRemark',
                                        data: { title: '终审', uuid: record.uuid, actionRef },
                                    })
                                }
                            >
                                终审
                            </Button>
                        ),
                    ]
                },
            },
        ],
    }

    const UpData = {
        added: 'posSampleItemAddSampleItemAttachment',
        columns: [
            {
                dataIndex: 'sampleItemUuid',
                title: 'sampleItemUuid',
                valueType: 'hidden',
                hideInSearch: true,
                hideInTable: true,
            },
            {
                dataIndex: 'attachmentUuid',
                title: '样品报告附件',
                valueType: 'upload',
                valueFile: [1, 2, 3, 4, 5],
                fileUrl: 'fileUrl',
                rules: true,
                hideInTable: true,
            },
            {
                dataIndex: 'fileUrl',
                title: '样品附件',
                valueType: 'hidden',
                hideInSearch: true,
                hideInTable: true,
                hideInAdded: true,
                hideInModify: true,
                width: 400,
            },
        ],
    }

    const { runAsync } = useRequest(Http, { manual: true })
    const onSubmit = () => {
        runAsync({ url: 'posSampleAddSampleFlowRecord', data: { status: 4, sampleUuid: record.uuid } }).then(() =>
            message.success('完成报告审核'),
        )
    }
    const [IndexNumber, setIndexNumber] = useState(1)
    const [SizeNumber, setSizeNumber] = useState(Parmas.pageSize || 10)
    if (CData) {
        return (
            <div className="SampleModel SampleA05">
                <DescriptionsModal data={record} pageHeaderData={header} />
                <div className="Tables">
                    <ProTable
                        actionRef={actionRef}
                        columns={DataList.columns(CData)}
                        params={Parmas}
                        request={async (params = {}) => {
                            delete params.current
                            params.sampleUuid = record.uuid
                            params.pageIndex = IndexNumber ?? 1
                            params.pageSize = SizeNumber ?? 10
                            return request(DataList.get, { params, headers }).then(data => {
                                if (data.list) return { data: data.list, total: data.total, success: true }
                                else return { data, success: true }
                            })
                        }}
                        pagination={{
                            pageSize: SizeNumber,
                            showSizeChanger: true,
                            onChange: (e, a) => {
                                setIndexNumber(e)
                                setSizeNumber(a)
                            },
                        }}
                        columnsState={{ persistenceKey: 'pro-table-singe-demos', persistenceType: 'localStorage' }}
                        rowKey="uuid"
                        search={false}
                        scroll={{ x: 800, y: 400 }}
                    />
                </div>
                <div className="Submit">
                    {Permission.findIndex(v => v.uuid === 'f37f9953-32b8-44b7-8cd3-b91b1497470d') !== -1 && (
                        <Button type="primary" onClick={onSubmit}>
                            完成报告审核
                        </Button>
                    )}
                </div>
                <ModalBox OptionsCall={OptionsCall} actionRef={actionRef} configure={UpData} />
            </div>
        )
    }
}

export const SampleDisposeModel = ({ data, Off }) => {
    const { record, actionRef } = data
    const { uuid, disposal, saveDate, disposalRemark } = record
    console.log('disposalRemark', disposalRemark)
    const [Value, setValue] = useState({
        uuid,
        disposal: disposal || '',
        saveDate: saveDate || new Date(),
        disposalRemark: disposalRemark || '',
    })
    const { runAsync } = useRequest(Http, { manual: true })
    const onSubmit = () => {
        runAsync({ url: 'posSampleItemAddDisposal', data: Value }).then(() => {
            actionRef.current.reload()
            Off()
        })
    }

    return (
        <div className="SampleDisposeModel">
            <div className="Label">
                <div>处置方式 : </div>
                <Input
                    defaultValue={Value.disposal}
                    onChange={e => setValue(data => ({ ...data, disposal: e.target.value }))}
                />
            </div>
            <div className="Label">
                <div>保存截止日期 : </div>
                <DatePicker
                    defaultValue={dayjs(Value.saveDate)}
                    onChange={e => setValue(data => ({ ...data, saveDate: e.format('YYYY-MM-DD') }))}
                />
            </div>
            <div className="Label">
                <div>处置备注 : </div>
                <TextArea
                    defaultValue={Value.disposalRemark}
                    autoSize={{ minRows: 4 }}
                    onChange={e => setValue(data => ({ ...data, disposalRemark: e.target.value }))}
                />
            </div>
            <div className="Submit">
                <Button type="primary" onClick={onSubmit}>
                    保存数据
                </Button>
            </div>
        </div>
    )
}

// 六、样品处理
export const SampleA06 = ({ data }) => {
    const { header, record, Permission } = data
    console.log('[数据权限]', Permission)
    const actionRef = useRef()
    const [OptionsCall, setOptionsCall] = useState()
    // const [Parmas] = useState({ pageIndex: 1, pageSize: 10 })
    const headers = { Authorization: sessionStorage.getItem('TOKEN') }
    const [CData, setCData] = useState()
    useMount(async () => {
        setCData(await LabReportTemplates())
    })
    const OptionsEvent = useEventEmitter()
    OptionsEvent.useSubscription(val => setOptionsCall(val))

    const DataList = {
        hideInSearch: true,
        pageSize: 10,
        params: { sampleUuid: record.uuid },
        get: API_LIST([record.uuid])['getSampleItem'],

        columns: data => [
            commonTableList.uuid,
            {
                dataIndex: 'sampleUuid',
                title: '样品编号',
                type: 'hidden',
                hideInTable: true,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                width: 150,
            },
            {
                dataIndex: 'displayNo',
                title: '样品编号',
                type: 'hidden',
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                width: 150,
            },
            // {
            //     dataIndex: 'serialNo',
            //     title: '报告编号',
            //     type: 'hidden',
            //     hideInSearch: true,
            //     hideInAdded: true,
            //     hideInModify: true,
            //     width: 150,
            // },
            {
                dataIndex: 'tableName',
                title: '样品名称',
                valueType: 'input',
                rules: true,
                width: 150,
            },
            {
                dataIndex: 'spec',
                title: '规格型号',
                valueType: 'input',
                hideInSearch: true,
                width: 100,
            },
            {
                dataIndex: 'num',
                title: '数量',
                valueType: 'inputNumber',
                rules: true,
                hideInSearch: true,
                width: 100,
            },
            {
                dataIndex: 'unit',
                title: '单位',
                valueType: 'input',
                hideInSearch: true,
                rules: true,
                width: 80,
            },
            // {
            //     dataIndex: 'labReportTemplateUuid',
            //     title: '报告名称',
            //     valueType: 'select',
            //     valueEnum: data.LabReportEnum,
            //     rules: true,
            //     hideInSearch: true,
            //     width: 200,
            // },
            // {
            //     dataIndex: 'selectedTestTypeNames',
            //     title: '检测参数',
            //     type: 'hidden',
            //     hideInSearch: true,
            //     hideInAdded: true,
            //     hideInModify: true,
            //     width: 400,
            // },
            {
                dataIndex: 'disposal',
                title: '处置方式',
                valueType: 'input',
                rules: true,
                width: 150,
            },
            {
                dataIndex: 'saveDate',
                title: '保存截止日期',
                valueType: 'input',
                rules: true,
                width: 150,
            },
            {
                dataIndex: 'disposalRemark',
                title: '处置备注',
                valueType: 'textarea',
                rules: true,
                width: 150,
            },
            {
                dataIndex: 'disposalUserName',
                title: '处置人',
                valueType: 'textarea',
                rules: true,
                width: 150,
            },
            {
                dataIndex: 'disposalDataTime',
                title: '操作日期',
                valueType: 'textarea',
                rules: true,
                width: 150,
            },
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 120,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    return [
                        Permission.findIndex(v => v.uuid === 'f4e855bc-a339-4027-848b-b7a44ff427b5') !== -1 && (
                            <Button
                                key="dispose"
                                type="link"
                                onClick={() =>
                                    setOptionsCall({
                                        type: 'SampleDisposeModel',
                                        data: { title: '样品处理', record, actionRef },
                                    })
                                }
                            >
                                样品处理
                            </Button>
                        ),
                    ]
                },
            },
        ],
    }
    const AnnexList = {
        get: API_LIST()['getSampleReportAttachment'],
        added: 'posSampleReportAttachment',
        initialValues: { sampleUuid: record.uuid, tableName: 2 },
        columns: [
            {
                dataIndex: 'sampleUuid',
                title: 'SampleUuid',
                valueType: 'hidden',
                hideInSearch: true,
                hideInTable: true,
            },
            {
                dataIndex: 'tableName',
                title: 'tableName',
                valueType: 'hidden',
                hideInSearch: true,
                hideInTable: true,
            },
            {
                dataIndex: 'originalName',
                title: '名称',
                valueType: 'hidden',
                search: false,
                hideInAdded: true,
                hideInModify: true,
            },
            {
                dataIndex: 'createUserName',
                title: '上传人',
                valueType: 'hidden',
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
            },
            {
                dataIndex: 'createTime',
                title: '上传时间',
                valueType: 'hidden',
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
            },
            {
                dataIndex: 'attachmentUuid',
                title: '样品报告附件',
                valueType: 'upload',
                valueFile: [1, 2, 3, 4, 5],
                fileUrl: 'fileUrl',
                rules: true,
                hideInTable: true,
            },
            {
                dataIndex: 'fileUrl',
                title: '样品附件',
                valueType: 'hidden',
                hideInSearch: true,
                hideInTable: true,
                hideInAdded: true,
                hideInModify: true,
                width: 400,
            },
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 200,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { uuid, fileUrl } = record
                    return [
                        Permission.findIndex(v => v.uuid === '37ec50b2-f963-4181-ab17-d83115247b17') !== -1 &&
                            fileUrl && (
                                <AnnexButton OptionsEvent={OptionsEvent} key="see" url={fileUrl} title="查看附件" />
                            ),
                        Permission.findIndex(v => v.uuid === '3db60717-7a1f-4abb-b8ef-601083bd62ca') !== -1 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url="SampleReportAttachment"
                                uuid={uuid}
                            />
                        ),
                    ]
                },
            },
        ],
    }

    const { runAsync } = useRequest(Http, { manual: true })
    const onSubmit = () => {
        runAsync({ url: 'posSampleAddSampleFlowRecord', data: { status: 5, sampleUuid: record.uuid } }).then(() =>
            message.success('完成样品处置'),
        )
    }
    const [IndexNumber, setIndexNumber] = useState(1)
    const [SizeNumber, setSizeNumber] = useState(10)

    const [Parmas, setParmas] = useState()

    const [activeKey, setActiveKey] = useState('tab1')

    if (CData) {
        return (
            <div className="SampleModel SampleA06">
                <DescriptionsModal data={record} pageHeaderData={header} />
                <div className="Tables">
                    <ProTable
                        actionRef={actionRef}
                        columns={activeKey === 'tab1' ? DataList.columns(CData) : AnnexList.columns}
                        params={Parmas}
                        request={async (params = {}) => {
                            delete params.current
                            params.sampleUuid = record.uuid
                            params.pageIndex = IndexNumber ?? 1
                            params.pageSize = SizeNumber ?? 10

                            const get = activeKey === 'tab1' ? DataList.get : AnnexList.get
                            if (activeKey === 'tab2') params.tableName = 2

                            return request(get, { params, headers }).then(data => {
                                if (data.list) return { data: data.list, total: data.total, success: true }
                                else return { data, success: true }
                            })
                        }}
                        pagination={{
                            pageSize: SizeNumber,
                            showSizeChanger: true,
                            onChange: (e, a) => {
                                setIndexNumber(e)
                                setSizeNumber(a)
                            },
                        }}
                        toolbar={{
                            menu: {
                                type: 'tab',
                                activeKey,
                                items: [
                                    { key: 'tab1', label: '样品处置' },
                                    { key: 'tab2', label: '样品附件' },
                                ],
                                onChange: key => {
                                    actionRef.current.reload()
                                    setActiveKey(key)
                                    setParmas({
                                        active: key,
                                        pageIndex: 1,
                                        pageSize: 10,
                                    })
                                },
                            },
                            actions: [
                                Permission.findIndex(v => v.uuid === 'e66d7e53-52b2-4abb-81b3-270baa22f994') !== -1 &&
                                    activeKey === 'tab2' && (
                                        <AddDataButton
                                            OptionsEvent={OptionsEvent}
                                            type="primary"
                                            icon="add"
                                            title="添加附件"
                                        />
                                    ),
                            ],
                        }}
                        columnsState={{ persistenceKey: 'pro-table-singe-demos', persistenceType: 'localStorage' }}
                        rowKey="uuid"
                        search={false}
                        scroll={{ x: 800, y: 400 }}
                    />
                </div>
                <div className="Submit">
                    {Permission.findIndex(v => v.uuid === '14d08df7-46e2-4682-a68a-66d486284940') !== -1 && (
                        <Button type="primary" onClick={onSubmit}>
                            完成样品处置
                        </Button>
                    )}
                </div>

                <ModalBox OptionsCall={OptionsCall} actionRef={actionRef} configure={AnnexList} />
            </div>
        )
    }
}
